//
// Created by Administrator on 2023/11/15.
//
#include "iostream"

using namespace std;


const int N = 20;//对角线元素 2n-1 取20防止越界
int n;

char map[N][N];
bool col[N], p[N], q[N];

//cur代表的是行，我们只需要判断在哪一行中的哪一列(i)放置即可
//p,q 代表对角是否可以放置
void dfs(int cur) {
    if (cur == n) {
        for (int i = 0; i < n; ++i) {
            cout << map[i] << endl;
        }
        cout << endl;
    }
    for (int i = 0; i < n; i++) {
        if (!col[i] && !p[cur + i] && !q[i - cur + n]) {
            map[cur][i] = 'Q';
            //主副对角线是线性代数的内容 背过！
            col[i] = p[i + cur] = q[i - cur + n] = true;
            dfs(cur + 1);
            map[cur][i] = '.';//回溯
            col[i] = p[i + cur] = q[i - cur + n] = false;
        }
    }
}


int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            map[i][j] = '.';
        }
    }
    dfs(0);
}